<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .container {
            height: 100vh;
            width: 100vw;
            background-color: #fffae5;
            display: flex;
            align-items: center;
            justify-content: center;
        }

        .heartWrap {
            position: absolute;
        }

        .heart {
            position: absolute;
            background-color: #faa;
            animation: heartMove 1s linear infinite;
            animation-iteration-count: 1;
            animation-delay: var(--delay, 0);
            animation-fill-mode: forwards;
            transform-origin: center;
            opacity: 0;
            /* transition: all 1s linear; */
        }

        .heart:before,
        .heart:after {
            position: absolute;
            content: "";
            left: 6px;
            top: 0;
            width: 6px;
            height: 10px;
            background: inherit;
            border-radius: 15px 15px 0 0;
            transform-origin: 0 100%;
            transform: rotate(-45deg);
        }

        .heart:after {
            left: 0;
            transform-origin: 100% 100%;
            transform: rotate(45deg);
        }

        .late0 {
            --lateX: -0px;
            --delay: 0.2s;
        }

        .late1 {
            --lateX: -10px;
            --delay: 0.1s;
        }

        .late2 {
            --lateX: -20px;
        }

        .late3 {
            --lateX: 10px;
            --delay: 0.3s;
        }

        .late4 {
            --lateX: 20px;
            --delay: 0.4s;
        }

        @keyframes heartMove {
            0% {
                transform: scale(0.5);
                opacity: 0.1;
            }

            50% {
                transform: scale(1) translate(var(--lateX, 0px), -100px);
                opacity: 1;
            }

            100% {
                opacity: 0;
            }
        }
    </style>
</head>

<body>
    <div class="container">
        <div class="heart"></div>

    </div>
    <script>
        document.addEventListener('click', (e) => {
            const vNode = document.createElement('div');
            vNode.className = "heartWrap";
            Array.from(new Array(5), (_, index) => {
                const heart = document.createElement('div');
                heart.className = `heart late${index}`;
                heart.style.background = "#" + Math.random().toString(16).slice(-6);
                // heart.style.top = -index * 2 + 'px';
                vNode.appendChild(heart);
            });
            document.body.appendChild(vNode);
            vNode.style.top = e.pageY - 20 + "px";
            vNode.style.left = e.pageX - 10 + "px";
            setTimeout(() => {
                document.body.removeChild(vNode);
            }, 2000)
        })
    </script>
</body>

</html>